package exercise1;

import java.util.Collections;
import java.util.LinkedList;

public class Book implements Comparable {
	private String name;
	private double price;
	
	public Book(String name, double price) {
		super();
		this.name = name;
		this.price = price;
	}

	@Override
	public char compareTo(Book book) {
		
		 if(this.price > book.price) {
			return '>';
		}
		else if(this.price < book.price) {
			return '<';
		}
		else {
				return '=';
			}
	}
	
	public static void main(String[] args) {
		LinkedList bookList = new LinkedList();
		Book book1 = new Book("book1", 32);
		Book book2 = new Book("book2", 31);
		Book book3 = new Book("book3", 32);
		Collections.addAll(bookList, book1,book2,book3);
		Book book4 = new Book("book4", 32);
		for(Object obj:bookList) {
			Book book = (Book)obj;
			if(book4.compareTo(book) == '=') {
				System.out.println(book.name);
			}
		}
	}
}
